package SiTuQingYou.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import SiTuQingYou.dao.UserDao;
import SiTuQingYou.vo.User;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends BaseAction {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	
	
	protected void toLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String username = request.getParameter("login-username");
		String userpass = request.getParameter("login-password");
		
		//UserDao userdao = UserDao.getud();
		//userdao.toLogin(username, userpass);
		User user = UserDao.toLogin(username, userpass);
		
		
		if(user!=null)
		{
			HttpSession session = request.getSession();
			session.setAttribute("user", user);
			
			response.sendRedirect("/SiTuQingYou/index/index.jsp");
			//response.sendRedirect("www.baidu.com");
		}
		else
		{
			response.sendRedirect("/SiTuQingYou/anotherLogReg/login.jsp?x=1");
			//response.sendRedirect("www.163.com");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doDefault(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stubr
		
	}
}
